<template>
  <div class="login-page">
    <el-card class="login-card">
      <h2 class="login-title">系统登录</h2>
      <el-form
        ref="loginForm"
        :model="loginForm"
        :rules="loginRules"
        class="login-form"
      >
        <el-form-item prop="username">
          <el-input v-model="loginForm.username" placeholder="用户名" />
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            show-password
            placeholder="密码"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="login-btn" @click="login"
            >登录</el-button
          >
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { setToken } from '@/utils/auth'
export default {
  data () {
    return {
      loginForm: {
        username: 'admin',
        password: 'admin'
      },
      loginRules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ],
        password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  methods: {
    login () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          // 执行登录操作，可以在这里发送登录请求等
          setToken('token')
          this.$router.push({
            name: 'home',
            params: {}
          })
        } else {
          console.log('表单校验未通过')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-image: url(../../assets/login-bg.png);
  background-size: cover;
}

.login-card {
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(30px);
  width: 400px;
}

.login-title {
  text-align: center;
  margin-bottom: 20px;
  font-size: 18px;
}

.login-form {
  margin-top: 20px;
  .login-btn {
    margin: 10px 0px 10px 0px;
    letter-spacing: 2px;
    height: 40px;
    width: 100%;
  }
}
</style>
